package com.zhijian.medical.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.format.FastDateFormat;
import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.config.CommonConfig;
import com.zhijian.medical.entity.po.AgentiaCheckHistory;
import com.zhijian.medical.entity.vo.response.CodeVo;
import com.zhijian.medical.service.AgentiaCheckHistoryService;
import com.zhijian.medical.service.impl.AgentiaCheckHistoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

/**
 * 试剂-分子病理室试剂验收试验记录表 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2023-07-21 15:11:37
 */
@Slf4j
@Controller
@Api(tags = "试剂-分子病理室试剂验收试验记录表")
public class AgentiaCheckHistoryController {

    @Autowired
    private AgentiaCheckHistoryService service;

    @Autowired
    private CommonConfig commonConfig;

    /**
     * 获取最新编号们
     *
     * @return
     */
    @Response
    @GetMapping("/agentia/check/history/code")
    @ApiOperation("获取最新编号们")
    public CodeVo getNewCode() {
        CodeVo codeVo = new CodeVo();
        codeVo.setCode2(service.createNextCode());
        codeVo.setCode(AgentiaCheckHistoryServiceImpl.CODE_PREFIX);
        codeVo.setDw(commonConfig.getDw());
        codeVo.setVersion(commonConfig.getVersion());
        codeVo.setSaveTime(commonConfig.getSaveTime());
        codeVo.setZrr(commonConfig.getZrr());
        codeVo.setPublishDate(DateUtil.format(new Date(), FastDateFormat.getInstance("yyyy年MM月dd日")));
        codeVo.setExecuteDate(codeVo.getPublishDate());
        return codeVo;
    }

    /**
     * 新增or修改
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/agentia/check/history")
    @ApiOperation("新增or修改")
    public boolean insert(@RequestBody AgentiaCheckHistory param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.saveOrUpdate(param);
    }

    /**
     * 根据试剂ID查询
     *
     * @param agentiaId
     * @return
     */
    @Response
    @GetMapping("/agentia/check/history/{agentiaId}")
    @ApiOperation("根据试剂ID查询")
    public AgentiaCheckHistory selectById(@PathVariable("agentiaId") Long agentiaId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), agentiaId);
        return service.selectByAgentiaId(agentiaId);
    }

}